package com.linkoog.devtools.maven.dependency_folding;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;

import javax.swing.*;

public class SettingsConfigurable implements Configurable {
    private final SettingsState service;
    private SettingsComponent component;

    public SettingsConfigurable(Project project) {
        service = project.getService(SettingsState.class);
    }

    @Override
    public String getDisplayName() {
        return "Maven Dependency Collapse";
    }

    @Override
    public JComponent getPreferredFocusedComponent() {
        return component.getPreferredFocusedComponent();
    }

    @Override
    public JComponent createComponent() {
        component = new SettingsComponent();
        return component.getPanel();
    }

    @Override
    public boolean isModified() {
        return service.getCollapsedText() != component.getCollapsedText() ||
                service.isCollapsedByDefault() != component.isCollapsedByDefault();
    }

    @Override
    public void apply() {
        service.setCollapsedText(component.getCollapsedText());
        service.setCollapsedByDefault(component.isCollapsedByDefault());
    }

    @Override
    public void reset() {
        component.setCollapsedText(service.getCollapsedText());
        component.setCollapsedByDefault(service.isCollapsedByDefault());
    }

    @Override
    public void disposeUIResources() {
        component = null;
    }
}

